package com.mes.defece.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mes.common.pojo.MESResult;
import com.mes.defece.mapper.ProcessMapper;
import com.mes.defece.service.ProcessService;
import com.mes.pojo.defece.ProcessPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 侯伟豪
 * @Company 起点编程
 * @Description
 * @Time 2024/10/23 16:30
 */
@Service
public class ProcessServiceImpl implements ProcessService {
    @Autowired
    private ProcessMapper processMapper;
    @Override
    public MESResult selectAll(ProcessPojo process, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<ProcessPojo> processes = processMapper.selectAll(process);
        return MESResult.success(new PageInfo<>(processes));
    }

    @Override
    public MESResult addProcess(ProcessPojo process) {
        process.setProcessDocumentStatus(1);
        process.setProcessMaterialPerson(1);
        return MESResult.success(processMapper.insert(process));
    }

    @Override
    public MESResult selectById(Long processId) {
        return MESResult.success(processMapper.selectById(processId));
    }

    @Override
    public MESResult updateProcessById(ProcessPojo process) {
        return MESResult.success(processMapper.updateProcessById(process));
    }

    @Override
    public MESResult deleteById(Long processId) {
        ProcessPojo process = new ProcessPojo();
        process.setProcessId(processId);
        process.setProcessDocumentStatus(99);
        return MESResult.success(processMapper.deleteById(process));
    }
}